exports.capture = function(req, resp, onHandled) {
    do {
        var uid = req.uid;
        var enemy = +req.args.enemy;

        doPVP(uid, enemy, function(battleReport) {
            if( !battleReport ) {
                resp.code = 1; 
                resp.desc = 'pvp error';
                onHandled();
                return;
            }

            var playerInfo = gUserInfo.getUser(uid);
            var enemyInfo = gUserInfo.getUser(enemy);
                
            if( battleReport.success ) {
                var captureExpireTime = common.getTime() + gConfGlobal.PrisonInterval * 3600;
                var prison = {
                    uid: enemy,
                    name: enemyInfo.name,
                    headpic: enemyInfo.headpic,
                    timer: captureExpireTime,
                    output: gConfLevel[gUserInfo.getUser(enemy).level].PrisonOutPut,
                    award: common.wRand(gConfRuntime.PrisonAwardWeights),
                };
                
                var enemyPrison = {
                    uid: uid,
                    name: playerInfo.name,
                    headpic: playerInfo.headpic,
                    timer: captureExpireTime,
                    level: playerInfo.level,
                    fight_force: playerInfo.fight_force
                };

                gMessage.addMessage(enemy, {
                    'uid': uid, 
                    'type': 'prison',
                    'name': playerInfo.name,
                    'time': common.getTime(),
                    'replay': gReplay.addReplay(battleReport)
                });

                gMessage.addPrisonUpdate(enemy, enemyPrison);

                resp.data.prison = prison;
            }

            resp.data.battle = battleReport;
            onHandled();
        });
        return;
    }while(false);

    onHandled();
}

exports.get_target = function(req, resp, onHandled) {
    var targets = gRank.getPrisonTarget(req.uid);
    resp.data.targets = targets;
    onHandled();
}

exports.resist = function(req, resp, onHandled) {
    var uid = req.uid;
    var enemy = req.args.enemy;
    doPVP(uid, enemy, function(battleReport) {
        if( !battleReport ) {
            resp.code = 1; 
            resp.desc = 'pvp error';
            onHandled();
            return;
        }

        resp.data.battle = battleReport;
        onHandled();
    });
}
